import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;


public class ReadWriteFile {

	/**
	 * @param args
	 * @throws IOException 
	 * @throws InterruptedException 
	 */
	public static void main(String[] args) throws IOException, InterruptedException {
		// TODO Auto-generated method stub
		int i=0;
		DateFormat dateFormat2 = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
		writelog();
//		String datetime = dateFormat2.format(cal.getTime()).toString();
//		System.out.println(datetime);		
		Writer output;
		output = new BufferedWriter(new FileWriter("text.log",true));
//		output.append(datetime+"\r\n");
//		output.append("\r\n");
//		output.close();
		while(i++<10){
			Calendar cal = Calendar.getInstance();
			String datetime = dateFormat2.format(cal.getTime()).toString();			
			output.append(datetime+"\r\n");
			output.append("\r\n");
			System.out.println(datetime);
			Thread.sleep(1000);
		}
		output.close();
	}
        
        public static void writelog() throws IOException{
            File root = new File("log");
            root.mkdirs();
            String filename = "asterlog.txt";
            File child = new File(root, filename);
            child.createNewFile();            
            Writer output1;
            output1 = new BufferedWriter(new FileWriter(child,true));
            output1.append("le thanh hai\r\n");
            output1.close();
//            child.
        }

}
